package com.nova.bluetooth.ui.ai.translate;

import com.nova.bluetooth.helpUtils.LogUtil;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

public class NovaTransformLanguageCodeUtil {
    public static List<LanguageSelectBean> mAsrLanguageList;
    public static List<LanguageSelectBean> mTranslateLanguageList;

    // 静态初始化块
    static {
        //注意 ！！！ mAsrLanguageList 与 mTranslateLanguageList 语言名字要一定要一样，对应
        mAsrLanguageList = new ArrayList<>();
        mAsrLanguageList.add(new LanguageSelectBean(1, 1, "zh_cn", "普通话"));
        mAsrLanguageList.add(new LanguageSelectBean(2, 1, "en_us", "英语"));
        mAsrLanguageList.add(new LanguageSelectBean(3, 1, "ja_jp", "日语"));
//        mAsrLanguageList.add(new LanguageSelectBean(1, "vi_VN", "越南语"));
        mAsrLanguageList.add(new LanguageSelectBean(6, 1, "de_DE", "德语"));
        mAsrLanguageList.add(new LanguageSelectBean(7, 1, "es_es", "西班牙语"));
        mAsrLanguageList.add(new LanguageSelectBean(8, 1, "fr_fr", "法语"));
        mAsrLanguageList.add(new LanguageSelectBean(9, 1, "ko_kr", "韩语"));
        mAsrLanguageList.add(new LanguageSelectBean(10, 1, "ru-ru", "俄语"));
        mAsrLanguageList.add(new LanguageSelectBean(14, 1, "th_TH", "泰语"));
        mAsrLanguageList.add(new LanguageSelectBean(16, 1, "it_IT", "意大利语"));

        mAsrLanguageList.add(new LanguageSelectBean(11, 2, "cn_cantonese", "广东话"));
        mAsrLanguageList.add(new LanguageSelectBean(19, 2, "henanese", "河南话"));


        //百度翻译
        //注意 ！！！翻译 languageCode 不能重复
        mTranslateLanguageList = new ArrayList<>();
        mTranslateLanguageList.add(new LanguageSelectBean(1, "x2_xiaojuan", "讯飞小娟（免费）", "zh", "普通话"));
        mTranslateLanguageList.add(new LanguageSelectBean(2, "x2_catherine", " 凯瑟琳", "en", "英语"));
        mTranslateLanguageList.add(new LanguageSelectBean(3, "x2_zhongcun", "zhongcun", "jp", "日语"));
//        mTranslateLanguageList.add(new LanguageSelectBean("x2_zhongcun","zhongcun","jp","vie", "越南语"));
        mTranslateLanguageList.add(new LanguageSelectBean(6, "x2_christiane", "christiane", "de", "德语"));
        mTranslateLanguageList.add(new LanguageSelectBean(7, "x2_felisa", "felisa", "spa", "西班牙语"));
        mTranslateLanguageList.add(new LanguageSelectBean(8, "x2_mariane", "玛丽安", "fra", "法语"));
        mTranslateLanguageList.add(new LanguageSelectBean(9, "x2_miya", "miya", "kor", "韩语"));
        mTranslateLanguageList.add(new LanguageSelectBean(10, "x2_keshu", "keshu", "ru", "俄语"));
        mTranslateLanguageList.add(new LanguageSelectBean(14, "x2_suparut", "suparut", "th", "泰语"));
        mTranslateLanguageList.add(new LanguageSelectBean(16, "x2_lrina", "lrina", "it", "意大利语"));

        mTranslateLanguageList.add(new LanguageSelectBean(11, "x2_xiaoyue", "小月", "yue", "广东话"));
        mTranslateLanguageList.add(new LanguageSelectBean(19, "x2_xiaokun", "讯飞小坤", "zh_henan", "河南话"));
    }

    public static void setLanguageNameByWebId(List<CallTranslationLanguageListResult.DataDTO> webData) {
        if (webData == null || webData.isEmpty()) {
            LogUtil.e("setLanguageNameByWebId==>webData must not be null or empty");
            return;
        }

        //languageCode 不要去设置，因为百度翻译的code跟语音听写接口的code不一样，所以要单独设置

        for (CallTranslationLanguageListResult.DataDTO dataDTO : webData) {
            for (LanguageSelectBean bean : mAsrLanguageList) {
                if (dataDTO.getId() == bean.getWebId()) {
                    bean.setLanguageName(dataDTO.getLanguageName());
                    bean.setBroadcastContent(dataDTO.getBroadcastContent());
                    bean.setSpeakerCode(dataDTO.getSpeakerCode());
                    break;
                }
            }

            for (LanguageSelectBean bean : mTranslateLanguageList) {
                if (dataDTO.getId() == bean.getWebId()) {
                    bean.setLanguageName(dataDTO.getLanguageName());
                    bean.setBroadcastContent(dataDTO.getBroadcastContent());
                    bean.setSpeakerCode(dataDTO.getSpeakerCode());
                    break;
                }
            }
        }
    }


    public static LanguageSelectBean getAsrLanguageBeanByTranslateName(String translateName) {
        LanguageSelectBean mAsrLanguage = mAsrLanguageList.get(0);
        for (LanguageSelectBean bean : mAsrLanguageList) {
            if (bean.getLanguageName().equals(translateName)) {
                mAsrLanguage = bean;
                break;
            }
        }
        return mAsrLanguage;
    }

    public static LanguageSelectBean getTranslateBeanByAsrLanguageName(String asrLanguageName) {
        LanguageSelectBean mTranslate = mTranslateLanguageList.get(0);
        for (LanguageSelectBean bean : mTranslateLanguageList) {
            if (bean.getLanguageName().equals(asrLanguageName)) {
                mTranslate = bean;
                break;
            }
        }
        return mTranslate;
    }

    public static LanguageSelectBean getTranslateBeanByTranslateLanguageName(String translateName) {
        LanguageSelectBean mTranslate = mTranslateLanguageList.get(0);
        for (LanguageSelectBean bean : mTranslateLanguageList) {
            if (bean.getLanguageName().equals(translateName)) {
                mTranslate = bean;
                break;
            }
        }
        return mTranslate;
    }

    /**
     * 根据语言Code获取到语言名称
     *
     * @param isAsrLanguage
     * @param languageCode
     * @return
     */
    public static String getLanguageNameByCode(boolean isAsrLanguage, String languageCode) {
        if (isAsrLanguage) {
            for (LanguageSelectBean bean :
                    Objects.requireNonNull(NovaTransformLanguageCodeUtil.mAsrLanguageList)) {
                if (languageCode.equals(bean.getLanguageCode())) {
                    return bean.getLanguageName();
                }
            }
        } else {
            for (LanguageSelectBean bean :
                    Objects.requireNonNull(NovaTransformLanguageCodeUtil.mTranslateLanguageList)) {
                if (bean.getLanguageCode().equals(languageCode)) {
                    return bean.getLanguageName();
                }
            }
        }
        return "";
    }

    @Deprecated
    private static void setTranslateLanguageRobot(CallTranslationLanguageListResult.DataDTO dataDTO) {
        for (int i = 0; i < mTranslateLanguageList.size(); i++) {
            LanguageSelectBean bean = mTranslateLanguageList.get(i);
            if (dataDTO.getLanguageName().equals(bean.getLanguageName())) {
                mTranslateLanguageList.get(i).setSpeakerCode(dataDTO.getSpeakerCode());
                mTranslateLanguageList.get(i).setSpeakerName(dataDTO.getSpeakerName());
            }
        }

    }
}
